package hollycrm.com.uip;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import hollycrm.com.uip.databinding.ActivityServerConfigBinding;

public class ServerConfigActivity extends AppCompatActivity {

    private ActivityServerConfigBinding binding;

    private static final String NAME = "hollycrm.com.uip";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_server_config);
        binding.setConfig(Utils.getConfig(this,NAME, Context.MODE_PRIVATE));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_config,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == R.id.action_save) {
            Utils.saveConfig(this,binding.getConfig(), NAME,Context.MODE_PRIVATE);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
